<?php

use Phinx\Migration\AbstractMigration;

class CreateProduct extends AbstractMigration
{
    public function change()
    {
        $table = $this->table('product', ['id' => 'product_id']);
        $table->addColumn('category_id', 'integer', ['comment' => '分类ID'])
            ->addColumn('partner_id', 'integer', ['comment' => '商家ID'])
            ->addColumn('name', 'string', ['limit' => 100, 'comment' => '产品名称'])
            ->addColumn('description', 'text', ['null' => true, 'comment' => '产品描述'])
            ->addColumn('price', 'decimal', ['precision' => 12, 'scale' => 2, 'default' => '0.00', 'comment' => '产品价格'])
            ->addColumn('market_price', 'decimal', ['precision' => 12, 'scale' => 2, 'default' => '0.00', 'comment' => '市场价'])
            ->addColumn('images', 'text', ['null' => true, 'comment' => '产品图片，JSON格式'])
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'comment' => '状态：0=下架，1=上架'])
            ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序'])
            ->addColumn('created_at', 'timestamp', ['null' => true])
            ->addColumn('updated_at', 'timestamp', ['null' => true])
            ->addIndex(['category_id'])
            ->addIndex(['partner_id'])
            ->addIndex(['status'])
            ->create();
    }
} 